import { createApp } from "vue";
import App from "./App.vue";
import ElementPlus from "element-plus";
import * as ElIcon from "@element-plus/icons-vue";
import "element-plus/dist/index.css";
import { registerMicroApps, start } from "qiankun";
import { routeLocationKey } from "vue-router";
import router from "./router";
// import { store } from './utils/store'
// import microApps from './consts/microApps'
const app = createApp(App);
Object.keys(ElIcon).forEach((key) => {
  app.component(key, ElIcon[key]);
});

// 获取乾坤子应用
let appMenus = [];
let microApps = [];
let menus = null;
appMenus = JSON.parse(sessionStorage.getItem("appMenus"));
menus = JSON.parse(sessionStorage.getItem("menus"));
if (appMenus && appMenus.length > 0) {
  appMenus.forEach((item) => {
    microApps.push({
      name: item.name,
      // entry: "//localhost:8081/fe-" + item.name + "/",
      entry:  "//" + window.location.host + "/fe-" + item.name + "/",
      container: "#subapp-viewport",
      activeRule: "/" + item.name + "/",
      props: {
        menus: menus[item.code],
      },
    });

  });
}
console.log(microApps);

registerMicroApps(microApps);
// 启动乾坤
start({
  prefetch: "all",
  sandbox: {
    experimentalStyleIsolation: true,
  },
});
app.use(router);
app.use(ElementPlus);
app.mount("#app");
